using Habanero.Faces.Base;

namespace FireStarterModeller.UI
{
    public class DirectorySelectorMapper : ControlMapper
    {
        private readonly DirectorySelectorControl _directorySelectorControl;

        public DirectorySelectorMapper(IControlHabanero ctl, string propName, bool isReadOnly, IControlFactory factory) : base(ctl, propName, isReadOnly, factory)
        {
            _directorySelectorControl = (DirectorySelectorControl) ctl;
            AddHandlers();
        }

        private void AddHandlers()
        {
            _directorySelectorControl.FileSelectorTextBox.TextChanged += delegate { ApplyChangesToBusinessObject(); };
        }

        public override void ApplyChangesToBusinessObject()
        {
            _businessObject.SetPropertyValue(PropertyName, _directorySelectorControl.FileSelectorTextBox.Text);
        }

        protected override void InternalUpdateControlValueFromBo()
        {
            if (_businessObject != null)
                _directorySelectorControl.FileSelectorTextBox.Text = _businessObject.GetPropertyValueString(PropertyName);
        }
    }
}